<template>
  <div style="display: flex;flex-direction: row;">
    <!--<effect></effect>-->
    <div style="width: 40%">
      <el-card style=" margin: 10px">
        <span style="font-weight: bold ;color: seagreen">完善信息</span>
        <el-form ref="forms" :model="forms" label-width="80px">
          <el-form-item style="text-align: center" label-width="0">
            <el-upload
              class="avatar-uploader"
              action="http://127.0.0.1:8083/files/upload"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
            >
              <img v-if="forms.avatar" :src="forms.avatar" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="用户名">
            <el-tag >{{forms.username}}</el-tag>
          </el-form-item>
          <el-form-item label="昵称">
            <el-tag type="success">{{forms.nick}}</el-tag>
          </el-form-item>
          <el-form-item label="年龄">
            <el-tag type="success">{{forms.age}}</el-tag>
          </el-form-item>
          <el-form-item label="性别">
            <el-tag type="success">{{forms.sex}}</el-tag>
          </el-form-item>
          <el-form-item label="地址">
            <el-tag type="success">{{forms.address}}</el-tag>
        </el-form-item>
          <el-form-item label="个性签名" >
            <el-tag type="success">{{forms.introduce}}</el-tag>
          </el-form-item>
          <el-form-item label="注册时间">
            <el-tag type="info">{{forms.regtime}}</el-tag>
          </el-form-item>
          <div style="text-align: center">

            <el-button type="primary"  @click="open">编辑资料</el-button>
          </div>
        </el-form>


      </el-card>

      <el-dialog
        title="编辑个人资料"
        :visible.sync="DialogVisible"
        width="30%">
        <el-form label-width="120px" :model="forms">
          <el-form-item label="用户名" style="font-weight: bold">
            <el-input v-model="forms.username" style="width: 80%" disabled=""></el-input>
          </el-form-item>
          <el-form-item label="昵称" style="font-weight: bold">
            <el-input v-model="forms.nick" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="年龄" style="font-weight: bold">
            <el-input v-model="forms.age" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="性别" style="font-weight: bold">
            <el-input v-model="forms.sex" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="住址" style="font-weight: bold">
            <el-input v-model="forms.address" style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="个性签名" style="font-weight: bold">
            <el-input v-model="forms.introduce" style="width: 80%"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
    <el-button @click="DialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="updateUser">确 定</el-button>
  </span>
      </el-dialog>

    </div>

    <el-divider direction="vertical"></el-divider>
    <div style="margin-left: 100px;margin-top: 20px">
      <span style="font-weight: bold;color: deepskyblue;">我的文案</span>
      <div style="margin-top: 20px">
        <span>雨纷纷</span>
        <el-divider direction="vertical"></el-divider>
        <span>旧故里</span>
        <el-divider direction="vertical"></el-divider>
        <span>草木深</span>
      </div>
      <div style="margin-top: 60px">
        <span>头上一片晴天，心中一个想念</span>
        <el-divider content-position="left">少年包青天</el-divider>
        <span>拿得起，放得下，路在脚下往前跨。没有过不去的坎，只有放不下的人</span>
        <el-divider><i class="el-icon-mobile-phone"></i></el-divider>
        <span>为了无法计算的价值</span>
        <el-divider content-position="right">阿里云</el-divider>
        <span>没必要刻意遇见谁，也不急于遇见谁，更不勉强留住谁，一切顺其自然，最好的自己留给值得珍惜的人</span>
        <el-divider content-position="left">公子无双</el-divider>
        <span> 遇见的人多了，你才会明白哪些人值得用生命去珍惜，哪些人只适合绕道而行</span>
        <el-divider content-position="right">无名</el-divider>
      </div>
    </div>


  </div>
</template>

<script>
  import request from '../utils/request'
  import effect from '../views/Effect'
  import "../assets/index.css";
  export default {
    name: 'Person',
    components:{effect},
    data() {
      return {
        forms: { },
        DialogVisible:false

      }
    },
    created() {
      let str = sessionStorage.getItem('user') || '{}'
      this.forms = JSON.parse(str)


    },
    methods: {
      open(){

        this.DialogVisible=true

      },
      handleAvatarSuccess(res) {
        this.forms.avatar = res.data
        this.updateUser()
      },
      updateUser() {
        request.put('/user/updateUser', this.forms).then(res => {
          if (res.code === 20000) {
            this.$message({
              message: '更新成功',
              type: 'success'
            })
            this.DialogVisible=false
            sessionStorage.setItem('user', JSON.stringify(this.forms))
            // 触发Layout更新用户信息
            this.$emit('userInfo')
          } else {
            this.$message({
              type: 'error',
              message: res.msg
            })
          }
        })
      }
    }
  }
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
